using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Admin_ChiTietMonHoc : System.Web.UI.Page
{
    MonHocBUS mhBus = new MonHocBUS();
    BoMonBUS bmBus = new BoMonBUS();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ddlBoMon.DataSource = bmBus.LayMang_BoMon();
            ddlBoMon.DataTextField = "TenBoMon";
            ddlBoMon.DataValueField = "MaBoMon";
            ddlBoMon.DataBind();

            ddlBoMon.SelectedIndex = 0;
            setMonHoc();
        }
    }
    public void setMonHoc()
    {       
        DataTable dt = mhBus.getBangMonHocChiTiet(ddlBoMon.SelectedIndex);
        if (dt.Rows.Count == 0)
            Label1.Visible = true;
        else
            Label1.Visible = false;
        gridMonHoc.DataSource = dt;
        gridMonHoc.DataBind();

        if (ddlBoMon.SelectedIndex != 0)
            gridMonHoc.Columns[4].Visible = false;
        else
            gridMonHoc.Columns[4].Visible = true;

        
    }

    //protected void Edit_Command(object source, DataListCommandEventArgs e)
    //{
    //    ItemsList.EditItemIndex = e.Item.ItemIndex;
    //    String maMonHoc = ((Label)e.Item.FindControl("lbMaMonHoc")).Text;
    //    String chuoiRandom = "1234567890";
    //    Random ran = new Random();
    //    String pass = "";
    //    for (int i = 0; i < 5; i++)
    //    {
    //        //string random co 10 ky tu
    //        int ind = ran.Next() % 10;
    //        pass += chuoiRandom[ind];
    //    }
    //    Response.Redirect("~/Admin/CapNhatMonHoc.aspx?idmh=" + maMonHoc + "&id=" + Math.Sqrt(Double.Parse(pass)));

    //}
    
    protected void btnXem_Click(object sender, EventArgs e)
    {
        setMonHoc();
    }
    protected void xemChiTietMonHoc(object sender, EventArgs e)
    {
        LinkButton lb = (LinkButton)sender;
        
        if (lb.CommandName == "xemChiTiet")
        {
            Response.Redirect("~/Admin/CapNhatMonHoc.aspx?idmh=" + lb.CommandArgument + "&id=" + Math.Sqrt(Double.Parse(chuoiRandom())));
        }
    }
    protected string chuoiRandom()
    {
        String chuoiRandom = "1234567890";
        Random ran = new Random();
        String pass = "";
        for (int i = 0; i < 5; i++)
        {
            //string random co 10 ky tu
            int ind = ran.Next() % 10;
            pass += chuoiRandom[ind];
        }
        return pass;
    }
}
